package study.函数式接口;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @Author 金贵权
 * @Date 2023/6/15 16:24
 **/
public class Demo04 {
    static Map<String, Function<Integer,Fruit>> map = new HashMap<>();
    static {
        map.put("apple",Apple::new);
        map.put("orange",Orange::new);
    }
    static Fruit setFruitWeight(String fruitName,Integer weight){
        return map.get(fruitName.toLowerCase()).apply(weight);
    }
    public static void main(String[] args) {
        Fruit apple = setFruitWeight("Apple", 32);
        Fruit orange = setFruitWeight("ORange", 36);
        System.out.println(apple+"和"+orange);

        FruitWeightFunction<String,Integer,String,Fruit> fruitWeightFunction = Fruit::new;
        List<String> fruitNameList = Arrays.asList("苹果", "香蕉", "桃子", "樱桃");
        List<Integer> fruitWeightList = Arrays.asList(10, 15, 20, 25, 30);
        List<String> fruitColorList = Arrays.asList("红色", "黑色", "白色", "蓝色", "紫色");
        for (String name : fruitNameList) {
            for (Integer weight : fruitWeightList) {
                for (String color : fruitColorList) {
                    Fruit fruit = fruitWeightFunction.apply(name, weight, color);
                    System.out.println("这是"+fruit.getColor()+"的"+fruit.getName()+",重量为"+fruit.getWeight());
                }
            }
        }
        Fruit apply = fruitWeightFunction.apply("香蕉", 39, "红色");
        System.out.println("这是"+apply.getColor()+"的"+apply.getName()+",重量为"+apply.getWeight());
    }
}
